package edu.unh.sustain;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class LinkedInActivity extends Activity{
WebView liWebView;
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.linkedin_main);

        liWebView = (WebView) findViewById(R.id.li_webview);
        liWebView.getSettings().setJavaScriptEnabled(true);
        liWebView.loadUrl(Constants.LINKEDIN_LINK);
        liWebView.setWebViewClient(new WebViewClient()
        {
            /**
             * loads URLs within the app, instead of the native browser
             */
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                view.loadUrl(url);
                return false;
            }
        });
    }
    
    /**
     * Handles the back button in the webview.  If it can go back to a previous
     * page, it does. If not, it will return to the Transportation menu.
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if(event.getAction() == KeyEvent.ACTION_DOWN)
        {
            switch(keyCode)
            {
                case KeyEvent.KEYCODE_BACK:
                    if(liWebView.canGoBack() == true)
                    {
                        liWebView.goBack();
                    }
                    else
                    {
                        finish();
                    }
                    return true;
            }
        }
        
        return super.onKeyDown(keyCode, event);
    }
}